//
// Created by 刘昱杉2020 on 2023/4/14.
//
#include "detect.h"
#include "test.h"

const char *lineStatusStr[] = {
        "",
        "straight",
        "left",
        "right",
        "big_left",
        "big_right",
        "cross",
        "no_line",
        "error"
};

//内部函数声明
uint16_t GPIO_read_multiple_pins(GPIO_TypeDef *GPIOx, uint16_t pin_mask);


//读取多路引脚状态
uint16_t GPIO_read_multiple_pins(GPIO_TypeDef *GPIOx, uint16_t pin_mask) {
    return (uint16_t)(GPIOx->IDR & pin_mask);
}
//将引脚封装在函数内 无外置形参
const char *Detect_GetState()
{   //此处若使用以0开始的GPIO 则解算失效 例程成立
    uint8_t state = GPIO_read_multiple_pins(TRACK_PORT,PORT1|PORT2|PORT3|PORT4|PORT5);
    LineStatus status;
    if (state == 0x08) //00100
        status = straight;
    else if (state == 0x04 || state == 0x0C) //00010 00110
        status = right;
    else if (state == 0x10 || state == 0x18) //01000 01100
        status = left;
    else if (state == 0x02) //00001
        status = big_right;
    else if (state == 0x20) //10000
        status = big_left;
    else if (state == 0x1C) //01110
        status = cross;
    else if (state == 0x00) //00000
        status = no_line;
    else
        status = error;

    return lineStatusStr[status];
}







